<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>四川干保保健</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="start/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="style/admin.css" media="all">
    <link rel="stylesheet" href="style/login.css" media="all">
    <style>
        html, body {
            font-family: webfont;
            height: 100%;
            background: url("dist/style/res/login_bg.jpg");
        }
    </style>
    <style>
    </style>
</head>
<body>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2 style="font-weight: bold;color: #005DA3">四川省干保保健2020</h2>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title">
                    <li class="layui-this">用户账户登录</li>
                </ul>

                <div class="layui-tab-content">
                    <!-- 用户名密码登录-->
                    <div class="layui-tab-item layui-show">
                        <div class="layui-form-item">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                                   for="LAY-user-login-username"></label>
                            <input type="text" name="username" id="LAY-user-login-username" lay-verify="required"
                                   placeholder="用户名" class="layui-input">
                        </div>
                        <div class="layui-form-item">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                                   for="LAY-user-login-password"></label>
                            <input type="password" name="password" id="LAY-user-login-password" lay-verify="required"
                                   placeholder="密码" class="layui-input">
                        </div>
                        <div class="layui-form-item" style="margin-bottom: 20px;">
                            <input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
                            <a href="forget.html" class="layadmin-user-jump-change layadmin-link"
                               style="margin-top: 7px;">忘记密码？</a>
                        </div>
                        <div class="layui-form-item">
                            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登
                                入
                            </button>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>

</div>

<script src="start/layui/layui.js"></script>
<script>
    layui.extend({
        sysconfig: 'dist/sysconfig'
        , appconfig: 'dist/appconfig'
    }).use(['layer', 'form', 'layer', 'appconfig', 'element'], function () {
        var $ = layui.$
            , setter = layui.setter
            , form = layui.form
            , layer = layui.layer
            , appconfig = layui.appconfig
            , element = layui.element;

        form.render();


        //提交
        form.on('submit(LAY-user-login-submit)', function (obj) {
            userLogin();
        });
        //键盘回车提交
        $(document).keyup(function (event) {
            if (event.keyCode === 13) {
                userLogin()
            }
        });


        function userLogin() {
            //加载弹窗
            var loading = layer.load(1, {
                content: "<div style='margin-left:-30px;padding-top:60px;width:120px;color:#2b425b;'>登录中请稍后...</div>",
                shade: [0.4, '#000']
            });

            var formObject = {};
            var formArray = $("#userInfo").serializeArray();
            $.each(formArray, function (i, item) {
                formObject[item.name] = item.value;
            });

            //用户名密码
            var username = $("#LAY-user-login-username").val();
            var password = $("#LAY-user-login-password").val();
            var jsonStr = {
                'loginAccount': username,
                "passWord": password
            };
            //请求登入接口
            $.ajax({
                url: appconfig.Login.login
                // url: "mockup/Role.json"
                , contentType: "application/json"
                , type: 'post'
                , data: JSON.stringify(jsonStr)
                , dataType: 'json'
                , success: function (result) {
                    layer.close(loading);
                    if (result.code !== "200") {
                        layer.msg(result.message, {
                            offset: '15px'
                            , icon: 2
                            , time: 1000
                        });
                    } else {
                        //数据存入缓存
                        sessionStorage.setItem("health-login-cache", JSON.stringify(result.data));
                        sessionStorage.setItem("health-login-cache-token",result.data.token);
                        //登入成功的提示与跳转
                        layer.msg('登入成功', {
                            offset: '15px'
                            , icon: 1
                            , time: 1000
                        }, function () {
                            location.href = 'start/index.html';
                        });
                    }
                }
                , error: function (e) {
                    let errorData = e.responseJSON;
                    layer.close(loading);
                    layer.msg(errorData.msg, {
                        offset: '15px'
                        , icon: 2
                        , time: 1000
                    });
                }
            });
        }
    });
</script>
</body>
</html>